package cn.stylefeng.guns.modular.web.controller;

import cn.stylefeng.guns.core.ParamUtil;
import cn.stylefeng.guns.modular.rw.entity.InfoSet;
import cn.stylefeng.guns.modular.rw.entity.MerToJoin;
import cn.stylefeng.guns.modular.rw.service.*;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述：招商加盟 controller
 * 作者：chenhuiyan
 * 时间：2020-05-09
 */
@Controller
@RequestMapping(value = "/web/merToJoin")
public class WebMerToJoinController extends BaseController {

    private String PREFIX = "/modular/web/";

    @Autowired
    private IInfoSetService infoSetService;

    @Autowired
    private IIndexBannerOneService indexBannerOneService;

    @Autowired
    private IBannerService bannerService;

    @Autowired
    private IMerToJoinService merToJoinService;

    /**
     * 跳转到首页
     */
    @RequestMapping(value = "/")
    public String index() {
        return PREFIX + "merToJoin.html";
    }

    /**
     * 初始化数据
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getInitData")
    public Map<String, Object> getInitData(){
        Map<String, Object> res = new HashMap<>();

        Map<String, Object> params = ParamUtil.getParams();

        //查询基本配置
        InfoSet infoSet = infoSetService.getBaseMapper().selectList(new QueryWrapper<InfoSet>()).get(0);

        //查询首页区块一
        Map<String, Object> indexBannerOne = indexBannerOneService.list(params).getRecords().get(0);

        //banner招商加盟背景图
        params.put("webType", "3");
        Map<String, Object> banner = bannerService.list(params).getRecords().get(0);

        res.put("infoSet", infoSet);
        res.put("indexBannerOne", indexBannerOne);
        res.put("banner", banner);

        return res;
    }

    /**
     * 保存加盟信息
     * @param merToJoin
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/submitMerToJoin")
    public Object submitMerToJoin(MerToJoin merToJoin){
        merToJoin.preInsert();
        merToJoinService.save(merToJoin);
        return SUCCESS_TIP;
    }

}
